<?php
/**
 * Description:获取用户标签相关
 * User: wh
 * Date: 2017-07-27
 * Time: 17:29
 */
namespace app\wxbackend\controller\Wx;

class WxTags
{
    /**
     * @comment 创建系统默认标签
     * @author wuhao
     * @param array $nameArr
     */
    public static function setDefaultTags($name)
    {
        $data = ['tag' => ['name' =>$name]];
        $data = json_encode($data, JSON_UNESCAPED_UNICODE);
        $access_token = WxAccessToken::getAccessToken();
        $url = "https://api.weixin.qq.com/cgi-bin/tags/create?access_token=".$access_token;
        $res = Curl::callWebServer($url, $data, 'POST');
        return $res;
    }
    /**
     * @comment 获取用户标签
     * @author wuhao
     */
    public static function getAllTags()
    {
        $access_token = WxAccessToken::getAccessToken();
        $url = "https://api.weixin.qq.com/cgi-bin/tags/get?access_token=".$access_token;
        $res = Curl::callWebServer($url, '', 'POST');
        return $res;
    }

    /**
     * @comment 设置用户标签
     * @author wuhao
     * @param array $openidArr
     * @param $tagId
     */
    public static function setTags(array $openidArr, $tagId)
    {
        $data = [
            'openid_list' => $openidArr,
            'tagid' => $tagId
        ];
        $data = json_encode($data);
        zft_log('wx/set_tags', $data);
        $access_token = WxAccessToken::getAccessToken();
        $url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=".$access_token;
        $res = Curl::callWebServer($url, $data, 'POST');
        return $res;
    }

    public static function cancelTags(array $openidArr, $tagId)
    {

        $data = [
            'openid_list' => $openidArr,
            'tagid' => $tagId
        ];
        $data = json_encode($data);
        zft_log('wx/cancel_tags', $data);
        $access_token = WxAccessToken::getAccessToken();
        $url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token=".$access_token;
        $res = Curl::callWebServer($url, $data, 'POST');
        return $res;
    }
}